﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Data.Linq;
using System.Data.Common;
using System.Transactions;
using System.Linq.Expressions;
using System.Collections;
using System.Runtime.Serialization;
using System.Xml;
using System.IO;
using System.Linq.Dynamic;
using Microsoft.Win32;
using System.Security.Permissions;
using System.Windows.Forms;
using System.Data;
using System.Data.Linq.Mapping;

namespace Srvtools
{
    [ToolboxItem(false)]
    public partial class LinqDataModule : Component, IDataModule
    {
        private object[] _clientInfo;
        private string _thisModuleName = "Srvtools";
        private string _thisComponentName = "LinqDataModule";

        public LinqDataModule()
        {
            InitializeComponent();
        }

        public LinqDataModule(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        private LinqCommand GetLinqCommand(string moduleName, string linqCommandName)
        {
            LinqCommand linqCommand = null;

            // 取ServerComp.Component类型
            Type type = GetType();
            if (type != null)
            {
                FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                for (int i = 0; i < fields.Length; i++)
                {
                    if (fields[i].Name.Equals(linqCommandName))
                    {
                        linqCommand = (LinqCommand)(fields[i].GetValue(this));
                        break;
                    }
                }
            }

            return linqCommand;
        }

        private Type GetEntityType(string moduleName, string linqCommandName)
        {
            LinqCommand linqCommand = GetLinqCommand(moduleName, linqCommandName);
            if (linqCommand == null)
            {
                return null;
            }

            string entityTypeName = linqCommand.EntityTypeName;

            string projectName = (string)((object[])_clientInfo[0])[6];

            string s = EEPRegistry.Server;
            if (s == "")
                s = Application.StartupPath;

            Assembly assembly = Assembly.LoadFrom(string.Format(@"{0}\{1}\{2}.dll", s, projectName, moduleName));

            Type entityType = assembly.GetType(entityTypeName);

            return entityType;
        }

        private DataContext GetDataContext(string moduleName, string linqCommandName)
        {
            LinqCommand linqCommand = GetLinqCommand(moduleName, linqCommandName);

            if (linqCommand == null)
            {
                return null;
            }

            // --------------------------------------------------------------------------
            // 取DataContextType
            string dataContextName = linqCommand.DataContextTypeName;
            string projectName = (string)((object[])_clientInfo[0])[6];

            string s = EEPRegistry.Server;
            if (s == "")
                s = Application.StartupPath;

            Assembly assembly = Assembly.LoadFrom(string.Format(@"{0}\{1}\{2}.dll", s, projectName, moduleName));

            Type dataContextType = assembly.GetType(dataContextName);

            // 创建DataContext
            return (DataContext)Activator.CreateInstance(dataContextType);
        }

        private IQueryable GetQueryable<E>(string moduleName, string linqCommandName, int skip, int take, string where, string orderBy, string groupByKey, string groupByElement, string select)
        {
            DataContext dataContext = GetDataContext(moduleName, linqCommandName);
            if (dataContext == null)
            {
                return null;
            }

            IQueryable query = dataContext.GetTable(typeof(E)).AsQueryable();
            if (!string.IsNullOrEmpty(where))
            {
                query = query.Where(where, new object[] { });
            }

            if (!string.IsNullOrEmpty(orderBy))
            {
                query = query.OrderBy(orderBy, new object[] { });
            }

            if (!string.IsNullOrEmpty(groupByKey) && !string.IsNullOrEmpty(groupByElement))
            {
                query = query.GroupBy(groupByKey, groupByElement, new object[] { });
            }

            if (!string.IsNullOrEmpty(select))
            {
                query = query.Select(select, new object[] { });
            }

            if (skip != -1)
            {
                query = query.Skip(skip);
            }

            if (take != -1)
            {
                query = query.Take(take);
            }

            return query;
        }

        //private IQueryable GetQueryable(string moduleName, string linqCommandName, Type type, int skip, int take, string where, string orderBy, string groupByKey, string groupByElement, string select)
        //{
        //    DataContext dataContext = GetDataContext(moduleName, linqCommandName);
        //    if (dataContext == null)
        //    {
        //        return null;
        //    }

        //    IQueryable query = dataContext.GetTable(type).AsQueryable();
        //    if (!string.IsNullOrEmpty(where))
        //    {
        //        query = query.Where(where, new object[] { });
        //    }

        //    if (!string.IsNullOrEmpty(orderBy))
        //    {
        //        query = query.OrderBy(orderBy, new object[] { });
        //    }

        //    if (!string.IsNullOrEmpty(groupByKey) && !string.IsNullOrEmpty(groupByElement))
        //    {
        //        query = query.GroupBy(groupByKey, groupByElement, new object[] { });
        //    }

        //    if (!string.IsNullOrEmpty(select))
        //    {
        //        query = query.Select(select, new object[] { });
        //    }

        //    if (skip != -1)
        //    {
        //        query = query.Skip(skip);
        //    }

        //    if (take != -1)
        //    {
        //        query = query.Take(take);
        //    }

        //    return query;
        //}

        private IQueryable GetQueryable(string moduleName, string linqCommandName, Type type, int skip, int take, string where, string orderBy, string groupByKey, string groupByElement, string select)
        {
            DataContext dataContext = GetDataContext(moduleName, linqCommandName);
            if (dataContext == null)
            {
                return null;
            }

            IQueryable query = dataContext.GetTable(type).AsQueryable();
            if (!string.IsNullOrEmpty(where))
            {
                query = query.Where(where, new object[] { });
            }

            if (!string.IsNullOrEmpty(orderBy))
            {
                query = query.OrderBy(orderBy, new object[] { });
            }

            if (!string.IsNullOrEmpty(groupByKey) && !string.IsNullOrEmpty(groupByElement))
            {
                query = query.GroupBy(groupByKey, groupByElement, new object[] { });
            }

            if (!string.IsNullOrEmpty(select))
            {
                query = query.Select(select, new object[] { });
            }

            if (skip != -1)
            {
                query = query.Skip(skip);
            }

            if (take != -1)
            {
                query = query.Take(take);
            }

            return query;
        }


        public void Insert(string moduleName, string linqCommandName, object[] instances)
        {
            DataContext dataContext = GetDataContext(moduleName, linqCommandName);
            if (dataContext == null)
            {
                return;
            }

            // 创建Transaction
            using (TransactionScope scope = new TransactionScope())
            {
                foreach (object entity in instances)
                {
                    Type entityType = entity.GetType();

                    dataContext.GetTable(entityType).InsertOnSubmit(entity);

                    dataContext.SubmitChanges();
                }

                scope.Complete();
            }
        }

        public void Update(string moduleName, string linqCommandName, object[] instances)
        {
            DataContext dataContext = GetDataContext(moduleName, linqCommandName);
            if (dataContext == null)
            {
                return;
            }

            // 创建Transaction
            using (TransactionScope scope = new TransactionScope())
            {
                foreach (object temp in instances)
                {
                    object[] os = (object[])temp;

                    object entity = os[0];
                    object oldEntity = os[1];

                    Type entityType = entity.GetType();
                    dataContext.GetTable(entityType).Attach(entity, oldEntity);

                    dataContext.SubmitChanges();
                }

                scope.Complete();
            }
        }

        public void Delete(string moduleName, string linqCommandName, object[] instances)
        {
            DataContext dataContext = GetDataContext(moduleName, linqCommandName);
            if (dataContext == null)
            {
                return;
            }

            // 创建Transaction
            using (TransactionScope scope = new TransactionScope())
            {
                foreach (object entity in instances)
                {
                    Type entityType = entity.GetType();

                    dataContext.GetTable(entityType).Attach(entity, false);

                    dataContext.GetTable(entityType).DeleteOnSubmit(entity);

                    dataContext.SubmitChanges(ConflictMode.ContinueOnConflict);
                }

                scope.Complete();
            }
        }


        //public void Insert(string moduleName, string linqCommandName, Type type, DataSet dataSet)
        //{
        //    object[] instances = ConvertToEntites(type, dataSet);

        //    DataContext dataContext = GetDataContext(moduleName, linqCommandName);
        //    if (dataContext == null)
        //    {
        //        return;
        //    }

        //    // 创建Transaction
        //    using (TransactionScope scope = new TransactionScope())
        //    {
        //        foreach (object entity in instances)
        //        {
        //            Type entityType = entity.GetType();

        //            dataContext.GetTable(entityType).InsertOnSubmit(entity);

        //            dataContext.SubmitChanges();
        //        }

        //        scope.Complete();
        //    }
        //}

        //public void Update(string moduleName, string linqCommandName, Type type, DataSet dataSet)
        //{
        //    object[] instances = ConvertToEntites(type, dataSet);

        //    DataContext dataContext = GetDataContext(moduleName, linqCommandName);
        //    if (dataContext == null)
        //    {
        //        return;
        //    }

        //    // 创建Transaction
        //    using (TransactionScope scope = new TransactionScope())
        //    {
        //        foreach (object temp in instances)
        //        {
        //            object[] os = (object[])temp;

        //            object entity = os[0];
        //            object oldEntity = os[1];

        //            Type entityType = entity.GetType();
        //            dataContext.GetTable(entityType).Attach(entity, oldEntity);

        //            dataContext.SubmitChanges();
        //        }

        //        scope.Complete();
        //    }
        //}

        //public void Delete(string moduleName, string linqCommandName, Type type, DataSet dataSet)
        //{
        //    object[] instances = ConvertToEntites(type, dataSet);

        //    DataContext dataContext = GetDataContext(moduleName, linqCommandName);
        //    if (dataContext == null)
        //    {
        //        return;
        //    }

        //    // 创建Transaction
        //    using (TransactionScope scope = new TransactionScope())
        //    {
        //        foreach (object entity in instances)
        //        {
        //            Type entityType = entity.GetType();

        //            dataContext.GetTable(entityType).Attach(entity, false);

        //            dataContext.GetTable(entityType).DeleteOnSubmit(entity);

        //            dataContext.SubmitChanges(ConflictMode.ContinueOnConflict);
        //        }

        //        scope.Complete();
        //    }
        //}

        public void Update(string moduleName, string linqCommandName, DataSet dataSet)
        {
            Type entityType = GetEntityType(moduleName, linqCommandName);
            DataContext dataContext = GetDataContext(moduleName, linqCommandName);
            if (dataContext == null)
            {
                return;
            }

            // 创建Transaction
            using (TransactionScope scope = new TransactionScope())
            {
                // Delete
                DataSet deletedDataSet = dataSet.GetChanges(DataRowState.Deleted);
                object[] deletedInstances = ConvertToEntites(entityType, deletedDataSet);
                foreach (object entity in deletedInstances)
                {
                    dataContext.GetTable(entityType).Attach(entity, false);

                    dataContext.GetTable(entityType).DeleteOnSubmit(entity);

                    dataContext.SubmitChanges(ConflictMode.ContinueOnConflict);
                }

                // Modity
                DataSet moditieddDataSet = dataSet.GetChanges(DataRowState.Modified);
                object[] moditiedInstances = ConvertToEntites(entityType, moditieddDataSet);
                foreach (object temp in moditiedInstances)
                {
                    object[] os = (object[])temp;

                    object entity = os[0];
                    object oldEntity = os[1];

                    dataContext.GetTable(entityType).Attach(entity, oldEntity);

                    dataContext.SubmitChanges();
                }

                // Insert
                DataSet insertedDataSet = dataSet.GetChanges(DataRowState.Added);
                object[] insertdInstances = ConvertToEntites(entityType, insertedDataSet);
                foreach (object entity in insertdInstances)
                {
                    dataContext.GetTable(entityType).InsertOnSubmit(entity);

                    dataContext.SubmitChanges();
                }


                scope.Complete();
            }
        }

        //public IList ExecuteSQL<R>(string moduleName, string linqCommandName, string sql)
        //{
        //    List<object> list = new List<object>();

        //    DataContext dataContext = GetDataContext(moduleName, linqCommandName);
        //    if (dataContext == null)
        //    {
        //        return list;
        //    }

        //    IQueryable query = dataContext.ExecuteQuery<R>(sql, new object[] { }).AsQueryable();

        //    // 取出Entity集合
        //    IEnumerator entities = query.GetEnumerator();
        //    while (entities.MoveNext())
        //    {
        //        object entity = entities.Current;
        //        list.Add(entity);
        //    }

        //    return list;
        //}

        //public IList ExecuteQuery<E, R>(string moduleName, string linqCommandName, int skip, int take, string where, string orderBy, string groupByKey, string groupByElement, string select)
        //{
        //    List<object> list = new List<object>();

        //    IQueryable query = GetQueryable<E>(moduleName, linqCommandName, skip, take, where, orderBy, groupByKey, groupByElement, select);

        //    // 取出Entity集合
        //    IEnumerator entities = query.GetEnumerator();
        //    while (entities.MoveNext())
        //    {
        //        object entity = entities.Current;
        //        if (entity is R)
        //        {
        //            list.Add(entity);
        //        }
        //        else
        //        {
        //            Type type0 = entity.GetType();
        //            Type type1 = typeof(R);       // result

        //            object result = Activator.CreateInstance(type1);

        //            PropertyInfo[] propertys1 = type1.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty);
        //            foreach (PropertyInfo property1 in propertys1)
        //            {
        //                string propertyName = property1.Name;

        //                PropertyInfo property0 = type0.GetProperty(propertyName, BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance);
        //                if (property0 != null && property0.PropertyType == property1.PropertyType)
        //                {
        //                    object propertyValue0 = property0.GetValue(entity, null);
        //                    property1.SetValue(result, propertyValue0, null);
        //                }
        //            }

        //            list.Add(result);
        //        }
        //    }

        //    return list;
        //}


        public DataSet ExecuteSQL(string moduleName, string linqCommandName, string sql)
        {
            DataSet dataSet = new DataSet();

            Type entityType = GetEntityType(moduleName, linqCommandName);
            DataContext dataContext = GetDataContext(moduleName, linqCommandName);
            if (dataContext == null)
            {
                return dataSet;
            }

            IQueryable query = dataContext.ExecuteQuery(entityType, sql, new object[] { }).AsQueryable();

            // 取出Entity集合
            IEnumerator entities = query.GetEnumerator();

            dataSet = ConvertToDataSet(entityType, entities);

            return dataSet;
        }

        public DataSet ExecuteQuery(string moduleName, string linqCommandName, int skip, int take, string where, string orderBy, string groupByKey, string groupByElement, string select)
        {
            Type entityType = GetEntityType(moduleName, linqCommandName);

            IQueryable query = GetQueryable(moduleName, linqCommandName, entityType, skip, take, where, orderBy, groupByKey, groupByElement, select);

            // 取出Entity集合
            IEnumerator entities = query.GetEnumerator();

            DataSet dataSet = ConvertToDataSet(entityType, entities);

            return dataSet;
        }

        //public DataSet ExecuteQuery(string moduleName, string linqCommandName, Type type, int skip, int take, string where, string orderBy, string groupByKey, string groupByElement, string select)
        //{
        //    DataSet dataSet = new DataSet();

        //    Hashtable propertiesTable = new Hashtable();

        //    #region 创建TableSchema

        //    object tableAttribute = type.GetCustomAttributes(typeof(TableAttribute), true);
        //    if (tableAttribute == null)
        //    {
        //        return dataSet;
        //    }
        //    string tableName = ((TableAttribute)tableAttribute).Name;
        //    if (string.IsNullOrEmpty(tableName))
        //    {
        //        return dataSet;
        //    }
        //    DataTable t = new DataTable(tableName);
        //    dataSet.Tables.Add(t);

        //    List<DataColumn> primaryKey = new List<DataColumn>();
        //    PropertyInfo[] propertys = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty);
        //    foreach (PropertyInfo property in propertys)
        //    {
        //        object obj = property.GetCustomAttributes(typeof(ColumnAttribute), true);
        //        if (obj == null)
        //        {
        //            continue;
        //        }
        //        ColumnAttribute columnAttribute = (ColumnAttribute)obj;

        //        string storage = columnAttribute.Storage;
        //        string dbType = columnAttribute.DbType;
        //        bool canBeNull = columnAttribute.CanBeNull;
        //        bool isPrimaryKey = columnAttribute.IsPrimaryKey;

        //        if (string.IsNullOrEmpty(storage))
        //        {
        //            continue;
        //        }

        //        DataColumn column = new DataColumn(storage);
        //        //column.DataType = 
        //        column.AllowDBNull = canBeNull;
        //        if (isPrimaryKey)
        //        {
        //            primaryKey.Add(column);
        //        }

        //        // 

        //        propertiesTable.Add(property.Name, storage);
        //    }

        //    if (primaryKey.Count != 0)
        //    {
        //        t.PrimaryKey = primaryKey.ToArray();
        //    }

        //    #endregion

        //    #region 转换为DataSet

        //    IQueryable query = GetQueryable(moduleName, linqCommandName, type, skip, take, where, orderBy, groupByKey, groupByElement, select);

        //    // 取出Entity集合
        //    IEnumerator entities = query.GetEnumerator();
        //    while (entities.MoveNext())
        //    {
        //        object entity = entities.Current;
        //        if (entity.GetType() == type)
        //        {
        //            DataRow row = t.NewRow();
        //            foreach (object key in propertiesTable.Keys)
        //            {
        //                string columnName = propertiesTable[key].ToString();

        //                PropertyInfo property = type.GetProperty(key.ToString());

        //                row[columnName] = property.GetValue(entity, null);
        //            }
        //            t.Rows.Add(row);
        //        }
        //    }

        //    #endregion

        //    return dataSet;
        //}

        public DataSet ConvertToDataSet(Type type, IEnumerator entities)
        {
            DataSet dataSet = new DataSet();

            List<string> properties = new List<string>();

            #region 创建TableSchema

            //object[] tableAttributes = type.GetCustomAttributes(typeof(TableAttribute), true);
            //if (tableAttributes == null || tableAttributes.Length == 0)
            //{
            //    return dataSet;
            //}

            //TableAttribute tableAttribute = (TableAttribute)tableAttributes[0];
            //string tableName = tableAttribute.Name;
            string tableName = type.Name;
            if (string.IsNullOrEmpty(tableName))
            {
                return dataSet;
            }
            DataTable t = new DataTable(tableName);
            dataSet.Tables.Add(t);

            List<DataColumn> primaryKey = new List<DataColumn>();
            PropertyInfo[] propertys = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty);
            foreach (PropertyInfo property in propertys)
            {
                object[] columnAttributes = property.GetCustomAttributes(typeof(ColumnAttribute), true);
                if (columnAttributes == null || columnAttributes.Length == 0)
                {
                    continue;
                }

                ColumnAttribute columnAttribute = (ColumnAttribute)columnAttributes[0];

                string storage = columnAttribute.Storage;
                string dbType = columnAttribute.DbType;
                bool canBeNull = columnAttribute.CanBeNull;
                bool isPrimaryKey = columnAttribute.IsPrimaryKey;

                if (string.IsNullOrEmpty(storage))
                {
                    continue;
                }

                DataColumn column = new DataColumn(property.Name);
                //column.DataType = 
                column.AllowDBNull = canBeNull;
                if (isPrimaryKey)
                {
                    primaryKey.Add(column);
                }
                t.Columns.Add(column);
                // 

                properties.Add(property.Name);
            }

            if (primaryKey.Count != 0)
            {
                t.PrimaryKey = primaryKey.ToArray();
            }

            #endregion

            #region 转换为DataSet

            while (entities.MoveNext())
            {
                object entity = entities.Current;
                if (entity.GetType() == type)
                {
                    DataRow row = t.NewRow();
                    foreach (string propertyName in properties)
                    {
                        PropertyInfo property = type.GetProperty(propertyName);

                        row[propertyName] = property.GetValue(entity, null);
                    }
                    t.Rows.Add(row);
                }
            }

            #endregion

            return dataSet;
        }

        public object[] ConvertToEntites(Type type, DataSet dataSet)
        {
            object[] instances = new object[] { };

            if (dataSet == null || dataSet.Tables.Count == null || dataSet.Tables[type.Name] == null)
            {
                return instances;
            }

            DataTable table = dataSet.Tables[type.Name];

            IQueryable query = table.AsEnumerable().AsQueryable();

            IEnumerator entities = query.GetEnumerator();

            List<object> list = new List<object>();
            while (entities.MoveNext())
            {
                list.Add(entities.Current);
            }

            return list.ToArray();
        }

        
        public object GetIntfObject(Type intfType)
        {
            object oRet = null;
            try
            {
                ReflectionPermission reflectionPerm1 = new ReflectionPermission(PermissionState.None);
                reflectionPerm1.Flags = ReflectionPermissionFlag.AllFlags;

                if (intfType.IsInterface)
                {
                    Type type = this.GetType();
                    FieldInfo[] myFields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                    for (int i = 0; i < myFields.Length; i++)
                    {
                        object newobj = myFields[i].GetValue(this);
                        if ((null != newobj) && (null != newobj.GetType().GetInterface(intfType.Name)))
                        {
                            return newobj;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                string sMess = SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), _thisModuleName, _thisComponentName, "msg_RethrowException");
                throw new Exception(string.Format(sMess, _thisModuleName, "GetIntfObject", e.Message));
            }
            return oRet;
        }

        public ArrayList GetIntfObjects(Type intfType)
        {
            ArrayList aRet = new ArrayList();
            try
            {
                ReflectionPermission reflectionPerm1 = new ReflectionPermission(PermissionState.None);
                reflectionPerm1.Flags = ReflectionPermissionFlag.AllFlags;

                if (intfType.IsInterface)
                {
                    Type type = this.GetType();
                    FieldInfo[] myFields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                    for (int i = 0; i < myFields.Length; i++)
                    {
                        object newobj = myFields[i].GetValue(this);
                        if ((null != newobj) && (null != newobj.GetType().GetInterface(intfType.Name)))
                        {
                            aRet.Add(newobj);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                string sMess = SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), _thisModuleName, _thisComponentName, "msg_RethrowException");
                throw new Exception(string.Format(sMess, _thisModuleName, "GetIntfObjects", e.Message));
            }
            return aRet;
        }

        public object GetClientInfo(ClientInfoType type)
        {
            if (this._clientInfo == null)
                return null;

            object[] o1 = (object[])this._clientInfo;
            if (o1[0] == null)
                return null;

            object[] o2 = (object[])o1[0];
            if (o2 == null)
                return null;

            if (type == ClientInfoType.ClientLang)
            {
                return o2[0];
            }
            else if (type == ClientInfoType.ComputerIp)
            {
                return o2[5];
            }
            else if (type == ClientInfoType.ComputerName)
            {
                return o2[4];
            }
            else if (type == ClientInfoType.CurrentProject)
            {
                return o2[6];
            }
            else if (type == ClientInfoType.LoginDB)
            {
                return o2[2];
            }
            else if (type == ClientInfoType.LoginUser)
            {
                return o2[1];
            }
            else if (type == ClientInfoType.SiteCode)
            {
                return o2[3];
            }
            else if (type == ClientInfoType.GroupID)
            {
                return o2[8];
            }
            else if (type == ClientInfoType.UserParam1)
            {
                return o2[9];
            }
            else if (type == ClientInfoType.UserParam2)
            {
                return o2[10];
            }
            else
            {
                return null;
            }
        }

        public object GetObjectByClassName(string sClassName)
        {
            object oRet = null;
            return oRet;
        }

        public ArrayList GetObjectsByClassName(string sClassName)
        {
            ArrayList oRet = null;
            return oRet;
        }

        public void SetClientInfo(object[] _ClientInfo)
        {
            _clientInfo = _ClientInfo;
        }

        public object[] GetClientInfo()
        {
            return _clientInfo;
        }

        public void SetOwnerComponent()
        {
            try
            {
                ArrayList myList = GetIntfObjects(typeof(IFindContainer));
                for (int i = 0; i < myList.Count; i++)
                {
                    ((IFindContainer)(myList[i])).OwnerComp = this;
                }
            }
            catch (Exception e)
            {
                string sMess = SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), _thisModuleName, _thisComponentName, "msg_RethrowException");
                throw new Exception(string.Format(sMess, _thisModuleName, "SetOwnerComponent", e.Message));
            }
        }
    }
}
